using System;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Threading;

namespace ReactiveLang.Util
{
    static class ThreadingUtil
    {
        public static IDisposable WriteLock(this ReaderWriterLockSlim @lock)
        {
            Contract.Requires(@lock != null);
            @lock.EnterWriteLock();
            return Disposable.Create(@lock.ExitWriteLock);
        }
        public static IDisposable ReadLock(this ReaderWriterLockSlim @lock)
        {
            Contract.Requires(@lock != null);
            @lock.EnterReadLock();
            return Disposable.Create(@lock.ExitReadLock);
        }
    }
}